package agend.client.gui.panels.settings;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.util.HashMap;

import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;

import agend.client.gui.panels.appointment.SxAppointmentPanel;
import agend.client.gui.utils.ErrorInterface;


/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class DialogFasciaOraria extends javax.swing.JDialog implements ErrorInterface {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private JComboBox comboFasciaDa;
	private JComboBox comboFasciaA;
	private JButton buttonAdd;
	
	private HashMap<String,String> model;
	private JLabel alleOreLabel;
	private JLabel dalleOreLabel;
	private JLabel titleLabel;

	public DialogFasciaOraria(JFrame frame) {
		super(frame,true);
		initGUI();
		model = new HashMap<String, String>();
		addListener();
	}
	
	private void addListener(){
		
		comboFasciaDa.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent arg0) {
				// TODO Auto-generated method stub
//				fillModel("START", comboFasciaDa.getSelectedItem().toString());
				
			}
		});
		
		comboFasciaA.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub
				
//				fillModel("END", comboFasciaA.getSelectedItem().toString());

			}
		});
		
		buttonAdd.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub
				//TODO Controllare che il modello non sia vuoto
				if(checkComboFasciaOraria())
				{
					fillModel("START", comboFasciaDa.getSelectedItem().toString());
					fillModel("END", comboFasciaA.getSelectedItem().toString());
					setVisible(false);
					dispose();
				}			
			}
		});
		
		this.addWindowListener(new WindowAdapter() {

			@Override
			public void windowClosing(WindowEvent e) {
				// TODO Auto-generated method stub
				super.windowClosing(e);
				if(model.containsKey("ITEMSTART"))
					model.remove("ITEMSTART");
				if(model.containsKey("ITEMEND"))
					model.remove("ITEMEND");
				
			}
			
		});
		
	}
	
	private void initGUI() {
		try {
			{
				
				GridBagLayout thisLayout = new GridBagLayout();
				thisLayout.columnWidths = new int[] {20, 7, 7, 7, 7};
				thisLayout.columnWeights = new double[] {0.1, 0.1, 0.1, 0.1, 0.1};
				thisLayout.rowWeights = new double[] {0.1, 0.0, 0.1, 0.1, 0.1};
				thisLayout.rowHeights = new int[] {7, 7, 20, 7, 20};
				getContentPane().setLayout(thisLayout);
				this.setPreferredSize(new java.awt.Dimension(542, 182));
				{
					
					comboFasciaDa = new JComboBox(new DefaultComboBoxModel<String>(SxAppointmentPanel.HOURS_MIN));
					getContentPane().add(comboFasciaDa, new GridBagConstraints(1, 3, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
				}
				{
					
					comboFasciaA = new JComboBox(new DefaultComboBoxModel<String>(SxAppointmentPanel.HOURS_MIN));
					getContentPane().add(comboFasciaA, new GridBagConstraints(3, 3, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
				}
				{
					buttonAdd = new JButton();
					getContentPane().add(buttonAdd, new GridBagConstraints(2, 4, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
					buttonAdd.setText("Add");
				}
				{
					titleLabel = new JLabel();
					getContentPane().add(titleLabel, new GridBagConstraints(1, 0, 3, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
					titleLabel.setText("Seleziona disponibilita' per il giorno scelto");
					titleLabel.setFont(new java.awt.Font("Segoe UI",1,14));
				}
				{
					dalleOreLabel = new JLabel();
					getContentPane().add(dalleOreLabel, new GridBagConstraints(1, 2, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
					dalleOreLabel.setText("Dalle ore");
				}
				{
					alleOreLabel = new JLabel();
					getContentPane().add(alleOreLabel, new GridBagConstraints(3, 2, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
					alleOreLabel.setText("Alle ore");
				}
			}
			this.setSize(542, 182);
			setVisible(false);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	
	public HashMap<String, String> getModel() {
		return model;
	}

	
	public void setModel(HashMap<String, String> model) {
		this.model = model;
	}

	public void fillModel(String key,String choiceCombo){
		
		
			model.put("ITEM"+key,choiceCombo);
//		String [] ris = choiceCombo.split(":");
//		model.put("HOURS"+key,Integer.parseInt(ris[0]));
//		model.put("MIN"+key,Integer.parseInt(ris[1]));
		
		
	}

	@Override
	public boolean checkIfAEmptyField() {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean checkIfDataGreaterThan() {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean checkComboBoxPreferenceSelected() {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean checkComboBoxTipologySelected() {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean checkComboFasciaOraria() {
		return ErrorInterface.error.checkComboFasciaOraria(comboFasciaDa, comboFasciaA);
	}

	@Override
	public boolean checkJSpinnerFasciaOraria() {
		// TODO Auto-generated method stub
		return false;
	}

}
